/*
 * 描          述:  <描述>
 * 修  改   人:  Administrator
 * 修改时间:  2019年4月30日
 * <修改描述:>
 */
package com.tx.core.starter.component;

import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration;
import com.tx.core.mybatis.automapper.AutoMPMapperRegister;
import com.tx.core.mybatis.autosqlmap.AutoSqlMapEntityDaoRegistry;
import com.tx.core.mybatis.support.MyBatisDaoSupport;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;

/**
 * 基础数据持久层配置逻辑<br/>
 * <功能详细描述>
 *
 * @author Administrator
 * @version [版本号, 2019年4月30日]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
@org.springframework.context.annotation.Configuration
@ConditionalOnBean({SqlSessionTemplate.class})
@AutoConfigureAfter({MybatisPlusAutoConfiguration.class, TransactionAutoConfiguration.class})
@Import({AutoSqlMapEntityDaoRegistry.class, AutoMPMapperRegister.class})
public class ComponentSupportAutoConfiguration {

    /** sqlSessionTemplate */
    private SqlSessionTemplate sqlSessionTemplate;

    /** <默认构造函数> */
    public ComponentSupportAutoConfiguration(SqlSessionTemplate sqlSessionTemplate) {
        super();
        this.sqlSessionTemplate = sqlSessionTemplate;
    }
    
    /**
     * 注册myBatisDaoSupport类<br/>
     *
     * @return
     * @throws Exception
     */
    @Bean({"tx.component.myBatisDaoSupport", "myBatisDaoSupport"})
    @ConditionalOnMissingBean(name = "tx.component.myBatisDaoSupport")
    public MyBatisDaoSupport myBatisDaoSupport() throws Exception {
        MyBatisDaoSupport myBatisDaoSupport = new MyBatisDaoSupport(
                this.sqlSessionTemplate);
        return myBatisDaoSupport;
    }
}
